<?php

/**
 * Taxamatch-Webservice PHP v1.0.0
 * @author Michael Giddens
 * @link http://www.silverbiology.com
 */

	
/**
 * Class Splitter
 */

Class Splitter 
{
	public $genus, $species, $author;

	public function __construct( $norm, $search_text ) {
		$cnts = json_decode( file_get_contents('http://globalnames.org/parsers.json?names=' . urlencode($search_text)) );
		$cnts = $cnts[0];
		if (isset($cnts->scientificName->details[0]->species->epitheton)) {
			$this->species = strtoupper( $cnts->scientificName->details[0]->species->epitheton );
			$this->genus = strtoupper( $cnts->scientificName->details[0]->genus->epitheton );
			if (isset($cnts->scientificName->details[0]->species->authorship)) {
				$this->author = $cnts->scientificName->details[0]->species->authorship;				
			} else {
				$this->author = '';
			}
		} else {
			$this->genus = strtoupper( $cnts->scientificName->details[0]->uninomial );
			if (isset($cnts->scientificName->details[0]->uninomial->authorship)) {
				$this->author = $cnts->scientificName->details[0]->uninomial->authorship;
			} else {
				$this->author = '';
			}
		}

	}
	public function get($field) {
		return $this->$field;
	}
}

?>